package logic

import (
	"context"
	"go-zero-demo-04/mall/result/api/ResultModel"

	//"go-zero-demo-04/mall/user/rpc/model"
	//"go-zero-demo-04/mall/user/rpc/user"
	//"google.golang.org/grpc/status"

	"go-zero-demo-04/mall/result/api/internal/svc"
	"go-zero-demo-04/mall/result/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type PutresultLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPutresultLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PutresultLogic {
	return &PutresultLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PutresultLogic) Putresult(req *types.PutresultRequest) (resp *types.PutresultResponse, err error) {
	newResult := ResultModel.TestResults{
		MbitCode:     req.MBTIcode,
		TestTime:     req.Time,
		StudentNo:    req.StudentID,
		StuidentName: req.StudentName,
		StudnetClass: req.StudentClass,
	}

	_, err = l.svcCtx.ResultModel.Insert(l.ctx, &newResult)

	if err != nil {
		return nil, err
	}

	return &types.PutresultResponse{
		Result: "存入成功",
	}, nil

}
